package com.tanhua.dubbo.api.mongo;

import com.tanhua.model.mongo.Questions;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@DubboService
public class QuestionsApiImpl implements QuestionsApi {
    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     * 根据难度等级查询问题
     *
     * @param level
     * @return
     */
    @Override
    public List<Questions> findQuestion(String level) {
        Query query=new Query();
        query.addCriteria(Criteria.where("level").is(level));
        List<Questions> questionsList = mongoTemplate.find(query, Questions.class);
        return questionsList;
    }
}

